package com.landeqing.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.Reader;

public class MyBatisUtils {
    public  static SqlSessionFactory getSqlSessionFactory() throws  Exception{
        String resource="mybatis-config.xml";
        Reader reader= Resources.getResourceAsReader(resource);
        SqlSessionFactoryBuilder builder=new SqlSessionFactoryBuilder();
        SqlSessionFactory sqlSessionFactory=  builder.build(reader);
        return sqlSessionFactory;
    }
    public static SqlSession getSqlSession() throws Exception {
        SqlSessionFactory sqlSessionFactory=getSqlSessionFactory();
        return sqlSessionFactory.openSession();
    }
    }

